﻿using NB.MGJ.Common.MVC;
using NB.MGJ.Model;
using NB.MGJ.Service.Origins;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NB.MGJ.Web.Controllers
{
    public class AuthController : BaseController
    {

        private OriginsAuthService _OriginsAuthService;
        public AuthController()
        {
            _OriginsAuthService = new OriginsAuthService();



        }

        public ActionResult AuthList_V()
        {
            return View();
        }

        public ActionResult AuthAdd_V(int Id=0)
        {
            ViewBag.AuthId = Id;
            return View();
        }



        public ActionResult GetAuthPageList(PagerModel pager)
        {
            var pageList = _OriginsAuthService.GetPageList(ref pager,LogOnUser);
            return Json(pageList);
        }

        public ActionResult AuthSave(L.EntityModel.Origins_Auth model)
        {
            if (model.Id == 0)
            {
                model.ChangeDate = DateTime.Now;
                model.ChangeLoginId = LogOnUser.UserID;
                model.ChangeLoginName = LogOnUser.RealName;
                model.EnterpriseId = LogOnUser.EnterpriseId;
                model.ViewDel = 0;

                var result = _OriginsAuthService.Add(model);
                return Json(result);
            }
            else
            {
            model.ChangeDate=DateTime.Now;
            model.ChangeLoginId=LogOnUser.UserID;
            model.ChangeLoginName=LogOnUser.RealName;
            model.ViewDel = 0;
            model.EnterpriseId = LogOnUser.EnterpriseId;
            var result=_OriginsAuthService.Update(model);
            return Json(model.Id);
            }

        }


        public ActionResult SelectAuthList ()
        {
            ViewBag.EID = LogOnUser.EnterpriseId;
            return View();
        }


        public ActionResult GetAuthListByEID()
        {
            var result = _OriginsAuthService.GetAuthListByEID(LogOnUser.EnterpriseId);
            return Json(result);
        }


        public ActionResult GetAuthModelByAuthId(int authId)
        {
            var model = _OriginsAuthService.GetModel(authId);
            return Json(model);
        }



	}
}